Update new agent form to include the service dropdown

When creating a new agent the service dropdown needs to be updated after
switing the agent type. Rendering the whole form and cherry picking just
the needed services dropdown seemed the easierst solution.

Dominik Sander 10 years ago
parent
commit
4ffd9ebb91

+ 2 - 0
app/assets/javascripts/application.js.coffee.erb

@@ -155,6 +155,8 @@ $(document).ready ->
155 155
 
156 156
         $(".description").html(json.description_html) if json.description_html?
157 157
 
158
+        $('.oauthable-form').html($(json.form).find('.oauthable-form').html()) if json.form?
159
+
158 160
         if $("#agent_options").hasClass("showing-default") || $("#agent_options").val().match(/\A\s*(\{\s*\}|)\s*\Z/g)
159 161
           window.jsonEditor.json = json.options
160 162
           window.jsonEditor.rebuild()

+ 7 - 6
app/controllers/agents_controller.rb

@@ -31,13 +31,14 @@ class AgentsController < ApplicationController
31 31
   end
32 32
 
33 33
   def type_details
34
-    agent = Agent.build_for_type(params[:type], current_user, {})
34
+    @agent = Agent.build_for_type(params[:type], current_user, {})
35 35
     render :json => {
36
-        :can_be_scheduled => agent.can_be_scheduled?,
37
-        :can_receive_events => agent.can_receive_events?,
38
-        :can_create_events => agent.can_create_events?,
39
-        :options => agent.default_options,
40
-        :description_html => agent.html_description
36
+        :can_be_scheduled => @agent.can_be_scheduled?,
37
+        :can_receive_events => @agent.can_receive_events?,
38
+        :can_create_events => @agent.can_create_events?,
39
+        :options => @agent.default_options,
40
+        :description_html => @agent.html_description,
41
+        :form => render_to_string(partial: 'form')
41 42
     }
42 43
   end
43 44
 

+ 8 - 6
app/views/agents/_form.html.erb

@@ -30,12 +30,14 @@
30 30
             <%= f.text_field :name, :class => 'form-control' %>
31 31
           </div>
32 32
 
33
-          <% if @agent.try(:oauthable?) %>
34
-            <div class="form-group type-select">
35
-              <%= f.label :service %>
36
-              <%= f.select :service_id, options_for_select(@agent.valid_services(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, @agent.service_id),{}, class: 'form-control' %>
37
-            </div>
38
-          <% end %>
33
+          <div class='oauthable-form'>
34
+            <% if @agent.try(:oauthable?) %>
35
+              <div class="form-group type-select">
36
+                <%= f.label :service %>
37
+                <%= f.select :service_id, options_for_select(@agent.valid_services(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, @agent.service_id),{}, class: 'form-control' %>
38
+              </div>
39
+            <% end %>
40
+          </div>
39 41
 
40 42
           <div class="form-group">
41 43
             <%= f.label :schedule, :class => 'control-label' %>